﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ODS.ViewModel
{
    public class TotalMessageViewModel : INotifyPropertyChanged
    {
        int totalMessage;

        public int TotalMessage
        {
            get { return totalMessage; }
            set {
                totalMessage = value;
                NotifyPropertyChanged("str_TotalMessage");
                NotifyPropertyChanged("TotalMessage");
            }
        }

        int totalUnreadMessage;

        public int TotalUnreadMessage
        {
            get { return totalUnreadMessage; }
            set {
                totalUnreadMessage = value;
                NotifyPropertyChanged("str_TotalUnreadMessage");
                NotifyPropertyChanged("TotalUnreadMessageFake");
                NotifyPropertyChanged("FontSizeUnreadMessage");
                NotifyPropertyChanged("IsShowNumberBadgeUnreadMessage");
            }
        }

        String str_totalMessage;

        public String str_TotalMessage
        {
            get {
                if (totalMessage > 1)
                {
                    str_totalMessage = totalMessage.ToString() + " Messages";
                }
                else
                {
                    str_totalMessage = totalMessage.ToString() + " Message";
                }
                return str_totalMessage;
            }
            set {
                str_totalMessage = value;
                NotifyPropertyChanged("str_TotalMessage");
            }
        }

        String str_totalUnreadMessage;

        public String str_TotalUnreadMessage
        {
            get {
                str_totalUnreadMessage = totalUnreadMessage.ToString() + " Unread";
                return str_totalUnreadMessage;
            }
            set {
                str_totalUnreadMessage = value;
                NotifyPropertyChanged("str_TotalUnreadMessage");
                NotifyPropertyChanged("TotalUnreadMessageFake");
                NotifyPropertyChanged("IsShowNumberBadgeUnreadMessage");
            }
        }

        String totalUnreadMessageFake;

        public String TotalUnreadMessageFake
        {
            get {
                if (totalUnreadMessage > 0 )
                    totalUnreadMessageFake = totalUnreadMessage.ToString();
                else
                    totalUnreadMessageFake = "";
                return totalUnreadMessageFake;
            }
            set {
                totalUnreadMessageFake = value;
                NotifyPropertyChanged("TotalUnreadMessageFake");
            }
        }

        Visibility isShowNumberBadgeUnreadMessage;

        public Visibility IsShowNumberBadgeUnreadMessage
        {
            get {
                if (totalUnreadMessage <= 0)
                    isShowNumberBadgeUnreadMessage = Visibility.Collapsed;
                else
                    isShowNumberBadgeUnreadMessage = Visibility.Visible;

                return isShowNumberBadgeUnreadMessage;
            }
            set {
                isShowNumberBadgeUnreadMessage = value;
                NotifyPropertyChanged("IsShowNumberBadgeUnreadMessage");

            }
        }

        int fontSizeUnreadMessage;

        public int FontSizeUnreadMessage
        {
            get {
                if (totalUnreadMessage >= 1000)
                {
                    fontSizeUnreadMessage = 14;
                }else
                    if (totalUnreadMessage >= 100)
                    {
                        fontSizeUnreadMessage = 18;
                    }
                    else
                    {
                        fontSizeUnreadMessage = 24;
                    }
                return fontSizeUnreadMessage;
            }
            set {
                fontSizeUnreadMessage = value;
                NotifyPropertyChanged("FontSizeUnreadMessage");
            }
        }

        ObservableCollection<MessageViewModel> messageViewModelList = new ObservableCollection<MessageViewModel>();

        public ObservableCollection<MessageViewModel> MessageViewModelList
        {
            get { return messageViewModelList; }
            set { messageViewModelList = value; }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
